<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>公告管理</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <script type="text/javascript" src="layui/layui.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>

</head>
<body>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
<script>
    layui.use(['table'], function () {
        var table = layui.table;
        layer = layui.layer;

        table.render({
            elem: '#test'
            , url: 'notice/all.do'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '用户数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', title: '编号', fixed: 'left', unresize: true, sort: true}
                , {field: 'content', title: '活动内容', edit: 'text'}
                , {field: 'createDate', title: '日期', edit: 'date'}
                , {field: 'title', title: '活动标题', edit: 'text'}
                , {field: 'uid', title: '管理员', edit: 'text'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
            ]]
            , page: true
        });

        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    $.ajax({
                        type: "get",
                        url: "notice/delete.do?id=" + data.id,
                        dataType: "json",
                        success: function (data) {
                            if (data.code === 0) {
                                layer.alert("删除成功")
                                location.reload()
                            }
                        }
                    })
                });
            } else if(obj.event === 'edit'){
                layer.alert('编辑行：<br>'+ JSON.stringify(data))
            }
        });
    });

</script>
</html>